package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 测试生命周期03，不指定初始化顺序。采用默认的规则：在servlet被选择时初始化
 */
@WebServlet(urlPatterns = "/life03", initParams = {
        @WebInitParam(name = "setChar", value = "utf-8")
})
public class DemoLife03Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    public void init() throws ServletException {
        System.out.println("life03 Servlet initialized.");
        super.init();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 打印执行日志
        System.out.println("life03 servlet service .....");
    }

    @Override
    public void destroy() {
        System.out.println("life03 Servlet destroyed.");
        super.destroy();
    }
}